package org.alino.core.utils;

import java.io.Serializable;

/**
 * @Desc TODO
 * @Author by Brant
 * @Date 2017/1/12
 */
public class ReturnUtils<T> implements Serializable {
    public static final int RETURN_CODE_SUCCESS = 0;
    public static final ReturnUtils<String> SUCCESS = new ReturnUtils<String>(0,"成功");
    public static final ReturnUtils<String> NOTLOGIN = new ReturnUtils<String>(-1,"没有登录");
    public static final ReturnUtils<String> PARAMS_ERROR = new ReturnUtils<String>(-2,"参数有误");
    public static final ReturnUtils<String> BUSINESS_RUN_ERROR = new ReturnUtils<String>(-3,"业务执行异常");
    public static final ReturnUtils<String> FAIL = new ReturnUtils<String>(-4, "失败");
    public static final ReturnUtils<String> LOCK_LOGIN = new ReturnUtils<String>(-7,"您处于锁定状态，请解锁！");
    public static final ReturnUtils<String> UNAUTHORIZED = new ReturnUtils<String>(-8,"没有权限，请联系管理员！");
    public static final ReturnUtils<String> KICKOUT_LOGIN = new ReturnUtils<String>(-9,"您已经被强制下线，请重新登录！");
    public static final ReturnUtils<String> OTHER_LOGIN = new ReturnUtils<String>(-10,"您已经在其他地方登录，请重新登录！");

    private int code;
    private String message;
    private T content;
    private Object extend;

    public ReturnUtils() {
    }

    public ReturnUtils(int code) {
        this.code = code;
    }

    public ReturnUtils(int code, String message, T content) {
        this.code = code;
        this.message = message;
        this.content = content;
    }
    public ReturnUtils(int code, String message, T content,Object extend) {
        this.code = code;
        this.message = message;
        this.content = content;
        this.extend = extend;
    }

    public ReturnUtils(int code, String message) {
        this.code = code;
        this.message = message;
        this.content = (T) "";
        this.extend = "";
    }

    public ReturnUtils(T content) {
        this.code = 0;
        this.message = "成功";
        this.content = content;
        this.extend = "";
    }

    public ReturnUtils(T content,Object extend) {
        this.code = 0;
        this.message = "成功";
        this.content = content;
        this.extend = extend;
    }

    public static ReturnUtils Success(Object content,Object extend){
        return new ReturnUtils(content,extend);
    }
    public static ReturnUtils Success(Object content){
        return new ReturnUtils(content,null);
    }
    public static ReturnUtils ParamsError(String message){
        return new ReturnUtils(-2,StringUtils.isBlank(message)?"参数有误":message);
    }
    public static ReturnUtils ParamsError(String message,Object extend){
        return new ReturnUtils(-2,StringUtils.isBlank(message)?"参数有误":message,"",extend);
    }
    public static ReturnUtils BusinessRunError(String message){
        return new ReturnUtils(-3,StringUtils.isBlank(message)?"业务执行异常":message);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getContent() {
        return content;
    }

    public void setContent(T content) {
        this.content = content;
    }

    public Object getExtend() {
        return extend;
    }

    public void setExtend(Object extend) {
        this.extend = extend;
    }
}
